package com.tianqu.tms.www.transfer.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.entity.TransferProcessHistory;
import com.tianqu.tms.entity.User;
import com.tianqu.tms.www.transfer.viewhelper.TransferRgInputViewHelper;

public class TransferSeniorSearchRecordAction extends TmsAction {
	private Logger logger = Logger.getLogger(TransferSeniorSearchRecordAction.class);
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		String serial = request.getParameter("serial");
		//根据流水号查询所有车辆信息 printHisList
		TransferRgInputViewHelper view = new TransferRgInputViewHelper();
		TransferAcceptedInfo accept = new TransferAcceptedInfo();
		accept = accept.getAcceptInfoBySerial(serial,"");
		view.setSerial(serial);
		User user = new User();
		if(accept!=null)
		{
			if(accept.getLc_printNum() > 0)
			{
				user = user.getUserInfoById(accept.getLc_printUserId());
				view.setLc_printNum(String.valueOf(accept.getLc_printNum()));
				view.setLc_printUser(user.getRealName());
				view.setLc_printTime(accept.getLc_printTime());			
			}else{
				view.setLc_printNum("0");
				view.setLc_printUser("-");
				view.setLc_printTime("-");					
			}
			
			if(accept.getCy_printNum() > 0)
			{
				//cha yan
				user = user.getUserInfoById(accept.getCy_printUserId());
				view.setCy_printNum(String.valueOf(accept.getCy_printNum()));
				view.setCy_printUser(user.getRealName());
				view.setCy_printTime(accept.getCy_printTime());			
			}else{
				view.setCy_printNum("0");
				view.setCy_printUser("-");
				view.setCy_printTime("-");					
			}
			if(accept.getPg_printNum() > 0)
			{
				//ping gu
				user = user.getUserInfoById(accept.getPg_printUserId());
				view.setPg_printNum(String.valueOf(accept.getPg_printNum()));
				view.setPg_printUser(user.getRealName());
				view.setPg_printTime(accept.getPg_printTime());			
			}else{
				view.setPg_printNum("0");
				view.setPg_printUser("-");
				view.setPg_printTime("-");					
			}
			if(accept.getDb_printNum() > 0)
			{
				//dai ban
				user = user.getUserInfoById(accept.getDb_printUserId());
				view.setDb_printNum(String.valueOf(accept.getDb_printNum()));
				view.setDb_printUser(user.getRealName());
				view.setDb_printTime(accept.getDb_printTime());			
			}else{
				view.setDb_printNum("0");
				view.setDb_printUser("-");
				view.setDb_printTime("-");					
			}
			
			if(accept.getZy_printnum() > 0)
			{
				//zhuan yi	
				user = user.getUserInfoById(accept.getZy_printUserId());
				view.setZy_printNum(String.valueOf(accept.getZy_printnum()));
				view.setZy_printUser(user.getRealName());
				view.setZy_printTime(accept.getZy_printTime());			
			}else{
				view.setZy_printNum("0");
				view.setZy_printUser("-");
				view.setZy_printTime("-");					
			}
			if(accept.getGh_printnum() > 0)
			{
				//zhuan yi	
				user = user.getUserInfoById(accept.getGh_printUserId());
				view.setGh_printNum(String.valueOf(accept.getGh_printnum()));
				view.setGh_printUser(user.getRealName());
				view.setGh_printTime(accept.getGh_printTime());			
			}else{
				view.setGh_printNum("0");
				view.setGh_printUser("-");
				view.setGh_printTime("-");					
			}	
		}else{
			view.setLc_printNum("0");
			view.setLc_printUser("-");
			view.setLc_printTime("-");	
			view.setCy_printNum("0");
			view.setCy_printUser("-");
			view.setCy_printTime("-");
			view.setPg_printNum("0");
			view.setPg_printUser("-");
			view.setPg_printTime("-");	
			view.setDb_printNum("0");
			view.setDb_printUser("-");
			view.setDb_printTime("-");	
			view.setZy_printNum("0");
			view.setZy_printUser("-");
			view.setZy_printTime("-");	
			view.setGh_printNum("0");
			view.setGh_printUser("-");
			view.setGh_printTime("-");
		}

		TransferProcessHistory his = new TransferProcessHistory();
		view.setLcList(his.loadtHistoryBySerial(serial));//历史记录
		request.setAttribute(TmsConstants.VIEWHELP,view);
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
